#include <osg/Notify>
#include <osg/NodeVisitor>
#include <osg/PositionAttitudeTransform>
#include "OLog.h"

class PrintNodeVisitor : public osg::NodeVisitor
{
public:
    PrintNodeVisitor() : osg::NodeVisitor(TRAVERSE_ALL_CHILDREN), _indent(0) {}

    void apply(osg::Node& node) override
    {
        printIndent();
        OLogI << "Node: " << node.className() << " (" << node.getName() << ")" << std::endl;
        
        _indent++;
        traverse(node);
        _indent--;
    }
    
    void apply(osg::Group& group) override
    {
        printIndent();
        OLogI << "Group: " << group.className() << " (" << group.getName() << ")"
                   << ", children: " << group.getNumChildren() << std::endl;
        
        _indent++;
        traverse(group);
        _indent--;
    }
    
    void apply(osg::PositionAttitudeTransform& pat) override
    {
        osg::Vec3d pos = pat.getPosition();
        osg::Quat att = pat.getAttitude();
        
        printIndent();
        OLogI << "PAT: " << pat.className() << " (" << pat.getName() << ")"
                   << ", position: (" << pos.x() << ", " << pos.y() << ", " << pos.z() << ")"
                   << ", attitude: (" << att.x() << ", " << att.y() << ", " << att.z() << ", " << att.w() << ")"
                   << ", children: " << pat.getNumChildren() << std::endl;
        
        _indent++;
        traverse(pat);
        _indent--;
    }

private:
    int _indent;
    
    void printIndent()
    {
        for (int i = 0; i < _indent; ++i)
            OLogI << "  ";
    }
};